package com.shuoyue.ycgk.ui.mine.collection;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.ChapterType;
import com.shuoyue.ycgk.entity.SectionType;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

public class ChapterAdapter extends AppBaseQuickAdapter<ChapterType> {

    public ChapterAdapter(@Nullable List<ChapterType> data) {
        super(R.layout.item_collection_type, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChapterType item) {
        helper.addOnClickListener(R.id.lay_title);
        helper.setText(R.id.title, item.getChapterName());
        helper.setImageResource(R.id.icon, item.isSelect() ? R.mipmap.arrow_up_blue_strok : R.mipmap.arrow_down_blue_strok);
        helper.setGone(R.id.recycler_view, item.isSelect());
        helper.setText(R.id.num, String.valueOf(item.getCount()) );

        RecyclerView recyclerView = helper.getView(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        if (recyclerView.getTag() == null) {
            recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 8), false));
            recyclerView.setTag("tag");
        }
        SectionAdapter childAdapter = new SectionAdapter(item.getWrongSectionDTOS());
        recyclerView.setAdapter(childAdapter);
        childAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            SectionType c = (SectionType) adapter.getItem(position);
            if (doquestions != null) {
                doquestions.questions(c.getSectionId(), c.getSectionName());
            }
        });
    }

    public void setDoquestions(Doquestions doquestions) {
        this.doquestions = doquestions;
    }

    private Doquestions doquestions;


    interface Doquestions {
        void questions(int sectionId, String name);
    }
}
